Events
Chat Events
It's possible to handle several events from SDK:
- UnreadMessagesCount
- ChatView
- ChatClose
- ProfessionalProfileView
- ChatMessageSent
- ChatMessageReceived
- appointment_user_booked
- appointment_user_cancelled
Events Implementing
UnreadMessagesCount can be captured calling it from Professionallist Sdk's component:
professionalList.setProfessionalListListener(object: ProfessionalList.ProfessionalListListener {
...
override fun onUnreadMessageCountChange(unreadMessageCount: Long) {
//Do your stuff
// note: 'unreadmessageCount' parameter means the total amount of user's unread messages
}
})
ChatView, ChatClose , ProfesisonalProfileView, ChatMessageSent, ChatMessageReceived, appointment_user_booked and appointment_user_cancelled events are captured via BroadcastReceiver. Each event has its own properties, the Intent of the BroadcastReceiver contains them:
-
ChatMessageSent & ChatMessageReceived Intent bundle properties: "eventType", "roomId", "professionalHash", "speciality", "specialityId", "messageType", "messageId" & "message".
-
ProfessionalProfileView Intent bundle properties: "eventType", "professionalHash", "speciality", "specialityId".
-
ChatView Intent bundle properties: "eventType", "roomId", "professionalHash", "speciality", "specialityId".
-
ChatClose Intent bundle properties: "eventType".
-
appointment_user_booked Intent bundle properties: "evenType", "appointmentId", "healthcareServiceId"
-
appointment_user_cancelled Intent bundle properties: "evenType", "appointmentId", "healthcareServiceId"
All the events also contain the property "timestamp" (Long)
// 1. Create your broadcast receiver
class EventAppBroadcastReceiver : BroadcastReceiver() {
var eventProperties: Bundle? = null
override fun onReceive(context: Context?, intent: Intent) {
// Capturing bundle from the intent
eventProperties = intent.extras
//e.g Show a toast message with info related to event 'ChatMessageReceived' by the professional
Toast.makeText(context, "Chat event type: ${eventProperties?.getString("eventType")} " +
"${eventProperties?.getString("speciality")} " +
"${eventProperties?.getInt("specialityId")} " +
"${eventProperties?.getString("messageType")} " +
"${eventProperties?.getString("message")} " +
"${eventProperties?.getLong("timestamp")}", Toast.LENGTH_LONG).show()
}
}
// 2. Declare your BroadcastReceiver on your Activity
val eventAppBroadCastReceiver: BroadcastReceiver = EventAppBroadcastReceiver()
// 3. Register your BroadcastReceiver, e.g. on your OnResume() method
LocalBroadcastManager.getInstance(this).registerReceiver(eventAppBroadCastReceiver,
IntentFilter(getString(R.string.meetingdoctors_local_broadcast_chat_events)))
// Optional. If its needed to stop capturing events, unregister your Broadcastreceiver, e.g. on your OnPause() method
LocalBroadcastManager.getInstance(this).unregisterReceiver(eventAppBroadCastReceiver)